<?xml-stylesheet href="resources/detached-style.css" media="screen"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title/>
</head>
<body onload="finishTest()">
<p><a href="https://bugs.webkit.org/show_bug.cgi?id=45205">Bug 45205</a>:
Test that &lt;xml-stylesheet> processing instructions only have stylesheets when in document.</p>
<pre id="result"></pre>
<script>
<![CDATA[
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

sheet = document.styleSheets[0];
pi = document.firstChild;
result = document.getElementById("result");

document.removeChild(pi);

function finishTest()
{
    result.innerHTML += "Not in document: " + ((pi.sheet === null) ? "PASS" : ("FAIL: " + pi.sheet)) + "\n";

    document.appendChild(pi);
    window.requestAnimationFrame(finishTest2);
}

var retryCount = 0;

function finishTest2() {
    // This subtest may fail because loading the resource may not complete immediately after
    // appendChild().
    if (pi.sheet === null && ++retryCount < 10) {
        window.requestAnimationFrame(finishTest2);
        return;
    }

    result.innerHTML += "After adding to document: " + ((pi.sheet === null) ? ("FAIL: " + pi.sheet) : "PASS") + "\n";
    result.innerHTML += "DONE";
    if (window.testRunner)
        testRunner.notifyDone();
}
]]>
</script>
</body>
</html>
